<?php
function getDb($connect = true)
{
	global $database;
    static $db = null;
    
	if(function_exists('mysqli_connect')){
		require_once(SYS_LIB . '/db/mysql/mysqli.class.php');
	}
	elseif (function_exists('mysql_connect')){
		require_once(SYS_LIB . '/db/mysql/mysql.class.php');
	}
	else{
		die("No extention for mysql or mysqli!");
	}
    if (null == $db){
	    $db =  new DbMySQL(
            $database['sql_host'], 
            $database['sql_user'], 
            $database['sql_pwd'], 
            $database['sql_db'],
            $database['sql_port']);
	    $db->debug = $database['sql_debug'];
	    $db->printErrMsg = $database['sql_print_error_sql'];
    }
	if ($connect) {
		$db->connect();
	}
	return $db;
}
?>